<?php


namespace api\controller;


use common\controller\VerifyController;
use common\exception\LogicException;
use common\service\InsideTaskReviewWorkflowService;
use common\service\OutsideTaskReviewWorkflowService;
use common\service\ReviewWorkflowService;
use think\Exception;
use think\Request;
use think\Response;

class ReviewWorkflowController extends VerifyController
{

    protected $reviewWorkflowService;

    public function __construct()
    {
        parent::__construct();
        $this->reviewWorkflowService = ReviewWorkflowService::getInstance();
    }

    /**
     * 删除工序流
     * @param Request $request
     * @return Response|void
     * @throws \Exception
     */
    public function delete(Request $request)
    {
        try {
            $resData = $this->reviewWorkflowService->delete($request->param());
            return json(success_response('', $resData));
        } catch (LogicException $e) {
            throw_strack_exception($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 查询审核流信息
     * @param Request $request
     * @return Response
     * @throws Exception
     */
    public function selectReviewWorkflow(Request $request)
    {
        $resData = $this->reviewWorkflowService->selectReviewWorkflow($request->param()['param']);
        return json(success_response('', $resData));
    }

    /**
     * 审核流查询测试
     * @param Request $request
     * @return Response
     * @throws Exception
     */
    public function selectReview(Request $request)
    {
        $type = $request->param()['param']['type'] ?? 'inside';
        $res = null;
        if ($type === 'outside') {
            $service = OutsideTaskReviewWorkflowService::getInstance();
            $res = $service->selectReview($request->param()['param']['task_id'], $request->param()['param']['order_id']);
        } elseif ($type === 'inside') {
            $service = InsideTaskReviewWorkflowService::getInstance();
            $res = $service->selectReview($request->param()['param']['task_id'], $request->getUserId());
        }
        return json(success_response('', $res));
    }
}
